package com.newbingo.action;

import java.util.List;

import com.googlecode.jsonplugin.annotations.JSON;
import com.newbingo.entity.Game;
import com.newbingo.entity.GamePlay;
import com.newbingo.service.imple.IGamePlayService;
import com.newbingo.util.Pager;
import com.opensymphony.xwork2.ActionSupport;

/**
 * GamePlayAction 处理游戏玩法action
 * @author ChansonYan
 *
 */
public class GamePlayAction extends ActionSupport {
	private IGamePlayService gamePlayService;
	private GamePlay gamePlay;
		/**
		 * 页面添加修改操作注入的属性
		 *  gamePlay.Id    Integer
		 *	gamePlay.name
		 *	gamePlay.playDesc
		 *	gamePlay.playScript
		 *	gamePlay.scriptType
		 *  gamePlay.game.gameno
		 */
	//分页查询条件，根据游戏显示页面传来的游戏编号gameno查询出所属游戏的编号的游戏玩法
	private int start;
	private int limit=10;
	private Integer gameno;
	private Pager pager;
	//获取操作是否成功
	private Boolean success=false;
	private List<GamePlay> plays;
	
	

	/**
	 * 根据游戏编号查询出游戏玩法
	 */
	public String findByGameNo(){
		setPlays(gamePlayService.findByGameNo(gameno));
		success=true;
		return SUCCESS;
	}
	
	/**
	 *创建游戏玩法action 
	 * @return
	 */
	public String create(){
		gamePlayService.createGamePlay(gamePlay);
		this.setGamePlay(null);
		success=true;
		return SUCCESS;
	}
	
	/**
	 * 
	 * 修改游戏玩法
	 */
	public String update(){
		if(gamePlay==null){
			success=false;
		}else{
			gamePlayService.updateGamePlay(gamePlay);
			success=true;
		}
		return SUCCESS;
	}
	
	
	/**
	 * 删除玩法
	 * @return
	 */
	public String delete(){
		gamePlayService.deleteGamePlay(gamePlay);
		success=true;
		return SUCCESS;
	}
	
	/**
	 * 分页查询
	 * 修改2009-8-8 改为由游戏的编号进行分页，前台要传入一个gameno参数过来
	 * @return
	 */
	public String findByPage(){
		setPager(gamePlayService.findByPage(start, limit, gameno));
		success=true;
		return SUCCESS;
	}
	
	public String findById(){
		setGamePlay(gamePlayService.findById(gamePlay.getId()));
		success=true;
		return SUCCESS;
	}


	public GamePlay getGamePlay() {
		return gamePlay;
	}
	public void setGamePlay(GamePlay gamePlay) {
		this.gamePlay = gamePlay;
	}
	public int getStart() {
		return start;
	}
	public void setStart(int start) {
		this.start = start;
	}
	public int getLimit() {
		return limit;
	}
	public void setLimit(int limit) {
		this.limit = limit;
	}
	
	public Pager getPager() {
		return pager;
	}

	public void setPager(Pager pager) {
		this.pager = pager;
	}

	@JSON(serialize=false)
	public IGamePlayService getGamePlayService() {
		return gamePlayService;
	}

	public void setGamePlayService(IGamePlayService gamePlayService) {
		this.gamePlayService = gamePlayService;
	}
	
	public Integer getGameno() {
		return gameno;
	}

	public void setGameno(Integer gameno) {
		this.gameno = gameno;
	}
	
	public Boolean getSuccess() {
		return success;
	}
	public void setSuccess(Boolean success) {
		this.success = success;
	}
	public List<GamePlay> getPlays() {
		return plays;
	}

	public void setPlays(List<GamePlay> plays) {
		this.plays = plays;
	}
	
}
